package com.mornd.gulimall.product.feign;

import com.mornd.gulimall.apis.product.IProductClient;
import com.mornd.gulimall.apis.product.to.SkuInfoTo;
import com.mornd.gulimall.apis.product.to.SpuInfoTo;
import com.mornd.gulimall.common.core.result.R;
import com.mornd.gulimall.product.entity.SkuInfo;
import com.mornd.gulimall.product.entity.SpuInfo;
import com.mornd.gulimall.product.service.ISkuInfoService;
import com.mornd.gulimall.product.service.ISkuSaleAttrValueService;
import com.mornd.gulimall.product.service.ISpuInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: mornd
 * @dateTime: 2023/8/20 - 10:13
 */

@RestController
public class ProductClientImpl implements IProductClient {
    @Resource
    private ISkuInfoService skuInfoService;
    @Resource
    private ISkuSaleAttrValueService skuSaleAttrValueService;
    @Resource
    private ISpuInfoService spuInfoService;

    @Override
    public R<SkuInfoTo> getSkuInfoById(Long skuId) {
        SkuInfo skuInfo = skuInfoService.getById(skuId);
        if(skuInfo == null) {
            return R.ok();
        }
        SkuInfoTo skuInfoTo = new SkuInfoTo();
        BeanUtils.copyProperties(skuInfo, skuInfoTo);
        return R.ok(skuInfoTo);
    }

    @Override
    public R<List<String>> getSkuSaleStringlist(Long skuId) {
        List<String> result =  skuSaleAttrValueService.getSkuSaleStringlist(skuId);
        return R.ok(result);
    }

    @Override
    public R<SpuInfoTo> getSpuInfo(Long spuId) {
        SpuInfo spuInfo = spuInfoService.getById(spuId);
        if(spuInfo == null) {
            return R.ok();
        }
        SpuInfoTo to = new SpuInfoTo();
        BeanUtils.copyProperties(spuInfo, to);
        return R.ok(to);
    }
}
